import collections
class Solution(object):
    def minFlips(self, s):
        t = 2 * s
        n = len(s)
        c1 = collections.Counter(s[::2])
        c2 = collections.Counter(s[1::2])
        odd1 = c1['1']
        odd0 = c1['0']
        even1 = c2['1']
        even0 = c2['0']
        min_len = min(odd0 + even1, odd1 + even0)
        for i in range(n):
            if t[i] == '1':
                odd1 -= 1
            else:
                odd0 -= 1
            odd1, odd0, even1, even0 = even1, even0, odd1, odd0
            if (n - 1) % 2 == 0:
                if t[i + n] == '1':
                    odd1 += 1
                else:
                    odd0 += 1
            else:
                if t[i + n] == '1':
                    even1 += 1
                else:
                    even0 += 1
            min_len = min(min_len, odd0 + even1, odd1 + even0)
        return min_len

data = Solution()
s = "0001101"
print(data.minFlips(s))